/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailItem.TargetConstraint;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ import java.util.Arrays;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MoveItem
/*     */   extends RedoableOp
/*     */ {
/*     */   private int[] mIds;
/*     */   private MailItem.Type type;
/*     */   private int mDestId;
/*     */   private String mConstraint;
/*  40 */   private int mUIDNEXT = -1;
/*     */   
/*     */   public MoveItem() {
/*  43 */     super(MailboxOperation.MoveItem);
/*  44 */     this.type = MailItem.Type.UNKNOWN;
/*  45 */     this.mDestId = 0;
/*  46 */     this.mConstraint = null;
/*     */   }
/*     */   
/*     */   public MoveItem(int mailboxId, int[] ids, MailItem.Type type, int destId, MailItem.TargetConstraint tcon) {
/*  50 */     this();
/*  51 */     setMailboxId(mailboxId);
/*  52 */     this.mIds = ids;
/*  53 */     this.type = type;
/*  54 */     this.mDestId = destId;
/*  55 */     this.mConstraint = (tcon == null ? null : tcon.toString());
/*     */   }
/*     */   
/*     */   public void setUIDNEXT(int uidnext) {
/*  59 */     this.mUIDNEXT = (uidnext > 0 ? uidnext : -1);
/*     */   }
/*     */   
/*     */   public int getUIDNEXT() {
/*  63 */     return this.mUIDNEXT;
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  68 */     StringBuilder sb = new StringBuilder("id=");
/*  69 */     sb.append(Arrays.toString(this.mIds)).append(", type=").append(this.type);
/*  70 */     sb.append(", dest=").append(this.mDestId);
/*  71 */     if (this.mConstraint != null) {
/*  72 */       sb.append(", constraint=").append(this.mConstraint);
/*     */     }
/*  74 */     if (this.mUIDNEXT != -1) {
/*  75 */       sb.append(", uidnext=").append(this.mUIDNEXT);
/*     */     }
/*  77 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/*  82 */     out.writeInt(-1);
/*  83 */     out.writeByte(this.type.toByte());
/*  84 */     out.writeInt(this.mDestId);
/*  85 */     boolean hasConstraint = this.mConstraint != null;
/*  86 */     out.writeBoolean(hasConstraint);
/*  87 */     if (hasConstraint) {
/*  88 */       out.writeUTF(this.mConstraint);
/*     */     }
/*  90 */     out.writeInt(this.mIds == null ? 0 : this.mIds.length);
/*  91 */     if (this.mIds != null) {
/*  92 */       for (int i = 0; i < this.mIds.length; i++) {
/*  93 */         out.writeInt(this.mIds[i]);
/*     */       }
/*     */     }
/*  96 */     if (getVersion().atLeast(1, 16)) {
/*  97 */       out.writeInt(this.mUIDNEXT);
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/* 103 */     int id = in.readInt();
/* 104 */     if (id > 0) {
/* 105 */       this.mIds = new int[] { id };
/*     */     }
/* 107 */     this.type = MailItem.Type.of(in.readByte());
/* 108 */     this.mDestId = in.readInt();
/* 109 */     if (in.readBoolean()) {
/* 110 */       this.mConstraint = in.readUTF();
/*     */     }
/* 112 */     if (id <= 0) {
/* 113 */       this.mIds = new int[in.readInt()];
/* 114 */       for (int i = 0; i < this.mIds.length; i++) {
/* 115 */         this.mIds[i] = in.readInt();
/*     */       }
/*     */     }
/* 118 */     if (getVersion().atLeast(1, 16)) {
/* 119 */       this.mUIDNEXT = in.readInt();
/*     */     }
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 125 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/*     */     
/* 127 */     MailItem.TargetConstraint tcon = null;
/* 128 */     if (this.mConstraint != null) {
/*     */       try {
/* 130 */         tcon = MailItem.TargetConstraint.parseConstraint(mbox, this.mConstraint);
/*     */       } catch (ServiceException e) {
/* 132 */         mLog.warn(e);
/*     */       }
/*     */     }
/*     */     
/* 136 */     mbox.move(getOperationContext(), this.mIds, this.type, this.mDestId, tcon);
/*     */   }
/*     */   
/*     */   public boolean isDeleteOp()
/*     */   {
/* 141 */     return this.mDestId == 3;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/MoveItem.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */